package offer;

import java.util.Deque;
import java.util.LinkedList;

public class offer58_I {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.reverseWords("a good   example");
    }


    static class Solution {
        public String reverseWords(String s) {
            s.trim();
            String[] arr = s.split(" ");
            Deque<String> stack = new LinkedList<>();
            for(String item : arr){
                if(item != ""){
                    stack.push(item);
                }
            }
            StringBuffer sb = new StringBuffer();
            for(String item : stack){
                sb.append(item+" ");
            }
            return sb.toString().trim();
        }
    }
}
